<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function getNow() {
            //格式化n年月日
            let d1 = new Date();
            let year = d1.getFullYear();
            let month = d1.getMonth() + 1;
            let date = d1.getDate();
            let day = d1.getDay();
            //格式化时分秒
            var h = d1.getHours();
            var m = d1.getMinutes();
            var s = d1.getSeconds();

            h = h < 10 ? '0' + h : h;
            m = m < 10 ? '0' + m : m;
            s = s < 10 ? '0' + s : s;

            let week = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'];

            return "今天是" + year + "年" + month + "月" + date + "日" + week[day] + ' '+ h + ':' + m + ':' + s;
        }
        console.log( getNow());
    </script>
</body>

</html>